define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'ground/index' + location.search,
                    add_url: 'ground/add',
                    edit_url: 'ground/edit',
                    del_url: 'ground/del',
                    multi_url: 'ground/multi',
                    import_url: 'ground/import',
                    table: 'ground',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'user.nickname', title: __('User.nickname')},
                        {field: 'type.name', title: __('场地类型'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'type_id', title: __('Type_id')},
                        {field: 'kefu', title: __('Kefu'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'city', title: __('City'), operate: false},
                        {field: 'address', title: __('Address'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'is_divide', title: __('Is_divide'), operate: false,searchList: {"1":__('Yes'),"0":__('No')}, formatter: Table.api.formatter.normal},
                        {field: 'updatetime', title: __('Updatetime'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'rs_time', title: __('Rs_time'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'rs_price', title: __('Rs_price'), operate:false},
                        // {field: 'js_time', title: __('Js_time'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'js_price', title: __('Js_price'), operate:false},
                        // {field: 'qs_time', title: __('Qs_time'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'qs_price', title: __('Qs_price'), operate:false},
                        // {field: 'yl_timed', title: __('Yl_timed'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'yl_djjg', title: __('Yl_djjg'),operate: false},
                        // {field: 'yl_cpp', title: __('Yl_cpp'),operate: false},
                        // {field: 'yl_kg', title: __('Yl_kg'),operate: false},
                        // {field: 'yinliang', title: __('Yinliang'),operate: false},
                        // {field: 'dg_start', title: __('Dg_start'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'dg_end', title: __('Dg_end'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},

                        {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons:[
                                {
                                    name: 'deviceset',
                                    text:'分成比例',//按钮名称
                                    title:'分成比例',//按钮名称
                                    classname: 'btn btn-xs btn-success btn-view btn-dialog',
                                    icon: 'fa fa-list',
                                    url: function (row) {
                                        return 'ground_child/index?ground_id='+row.id
                                    },
                                },


                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'ground/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), align: 'left'},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'ground/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'ground/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
